/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.design.structure.proxypattern.dynamicproxy.cglib;

/**
 * cglib 都是在运行时期生产字节码
 * jdk直接写字节码
 * cglib 使用ASM框架写Class字节码
 * jdk是通过反射调用的
 * cglib 是使用FastClass调用的
 *
 * 调用过程为：代理对象调用this.findLove()方法 -> 调用拦截器→methodProxy.invokeSuper()
 * -> CGLIB$findLove$0 -> 被代理对象findLove()方法。
 *
 * CGLib动态代理执行代理方法的效率之所以比JDK高，是因为CGlib采用了FastClass机制，
 * 它的原理简单来说就是：为代理类和被代理类各生成一个类，
 * 这个类会为代理类或被代理类的方法分配一个index（int类型）；这个index被当作一个入参，
 * FastClass可以直接定位要调用的方法并直接进行调用，省去了反射调用，因此调用效率比JDK动态代理通过反射调用高。
 * @author icanci
 * @date Created in 2021/07/16 08:01
 * @version 1.0
 */
public class CgTest {
    public static void main(String[] args) {
        CgZhangsan instance = (CgZhangsan) new CglibMeipo().getInstance(CgZhangsan.class);

        instance.findLove();
    }
}
